<template>
  <div :class="[isShow ? 'cart-submit-bar' : '']">
    <van-submit-bar button-text="去提货" :disabled="!canSubmit" class="submit-bar" @submit="onSubmit">
      <van-checkbox v-model="checked" class="posi"icon-size="18px" :checked-color="variables.theme">全选</van-checkbox>


      <slot name="warehouse" />
        <template #button>
          <div style="margin-left: 20px;">
            <slot />
            <van-button round color="linear-gradient(to right, #ff6034, #ee0a24)" @click="onSubmit">去提货</van-button>
          </div>
        </template>
    </van-submit-bar>
  </div>
</template>

<script>
import variables from '@/styles/variables.scss'

export default {
  props: {
    amount: {
      type: Number,
      default: 0
    },
    value: {
      type: Boolean,
      default: false
    },
    isShow: {
      type: Boolean,
      default: () => false
    },
    isCheckPurchase: {
      type: Boolean,
      default: () => false
    },
    timeFlag: {
      type: Boolean,
      default: () => false
    },
    slotName: {
      type: String,
      default: () => ''
    },
    checkTarget: {
      type: Object
    },
    normalProduct: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      disabled: false,
      allchecked: this.value
    }
  },
  computed: {
    variables() {
      return variables
    },
    checked: {
      get() {
        return this.allchecked
      },
      set(val) {
        this.allchecked = val
        this.$emit('input', val)
      }
    },
    canSubmit() {
      return this.amount > 0
    }
  },
  methods: {
    onSubmit() {
      if (this.isCheckPurchase) {
        this.$emit('settle')
        return
      }
      console.log('this.isCheckPurchase==', this.isCheckPurchase)
      console.log('this.checkTarget==', this.checkTarget)
      console.log('this.normalProduct==', this.normalProduct)

      if (!this.normalProduct) {
        return this.$toast.success('请选择一件商品')
      }
      this.$emit('pay')
      
    },
    addShelves() {
      this.$emit('add')
    },
    onConfirm(type) {
      this.$emit('confirm', type)
    }
  }
}
</script>

<style>
:root {
  --submit-bar-shadow: 0px -2px 10px 0px rgba(0, 0, 0, 0.08);
}
</style>

<style scoped>
.posi{
  position: absolute;
  left: 40px;
}

.submit-bar {
  /* 这里使用 css 函数，是为了避免旧版本 vue-cli 依赖的 css 压缩工具（mini-css-extract-plugin）导致的 bug */
  box-shadow: var(--submit-bar-shadow);
}

.van-submit-bar {
  /* bottom: 20px; */
}
</style>

<style scoped lang="scss">
.cart-submit-bar {
  //::v-deep .van-submit-bar__text {
  //  span {
  //    display: none;
  //  }
  //}
}

.mr-18 {
  margin-right: 18px;
}
</style>
